<?php

require_once(SRC_PATH."Object/Verb.php");
require_once(SRC_PATH."Object/VerbConjugation.php");
require_once("GenericReader.php");

class VerbConjugationReader extends GenericReader{
		
	public function __construct($object = NULL, $connection = NULL){
		parent::__construct($object, $connection);
	}
	
	public function execute(){
		$this->select = new RXSelect($this->connection);
		
		switch($this->operation){
			default:
				return $this->executeGetOne();			
		}
	}
	
	public function executeGetOne(){
		$query = "SELECT verb_conjugations.*, 
						 verb.id AS verb_id, 
						 verb.verb AS verb_verb
						 verb.is_reflexive AS verb_is_reflexive  
						 FROM verb_conjugations 
						 INNER JOIN verb ON verb.id = verb_conjugations.verb 
						 WHERE verb_conjugations.id = '".$this->object->getId()."'";
		$this->select->setQuery($query);
		return $this->select->execute();
	}
	
	public function next(){
		$row = $this->select->next();
		if($row){
			return new VerbConjugation(	$row["id"], 
																new Verb(	$row["verb_id"],	$row["verb_verb"], ($row["verb_is_reflexive"] == '1') ? TRUE : FALSE), 
																$row["conjugation"], 
																$row["person"], 
																$row["number"], 
																$row["time"], 
																$row["mode"]);
		}else{
			return FALSE;
		}
	}
}